package com.ruoyi.cloudsyncfile.utils;

import lombok.Data;

import java.util.Map;

/**
 * @ClassName BaseResult
 * @Description TODO
 * @Author wwf
 * @DATE 2024/8/14 15:08
 * @Version 1.0
 */
@Data
public class BaseResult {

    //表示接口是否请求成功
    private Boolean success;
    //响应状态码
    private  Integer code;
    //状态码描述信息
    private String msg;
    //返回的数据
    private Map<String,Object> data;


    //方法成功后的返回
    public static BaseResult successResult(){
        BaseResult baseResult = new BaseResult();
        baseResult.setSuccess(ResultCodeEnum.SUCCESS.getSuccess());
        baseResult.setCode(ResultCodeEnum.SUCCESS.getCode());
        baseResult.setMsg(ResultCodeEnum.SUCCESS.getMsg());
        return baseResult;
    }
    //操作失败后的返回
    public static BaseResult exceptionResult(){
        BaseResult baseResult = new BaseResult();
        baseResult.setSuccess(ResultCodeEnum.FAILURE.getSuccess());
        baseResult.setCode(ResultCodeEnum.FAILURE.getCode());
        baseResult.setMsg(ResultCodeEnum.FAILURE.getMsg());
        baseResult.setData(null);
        return  baseResult;
    }
    //系统错误返回
    public static BaseResult sysErrorResult(){
        BaseResult baseResult = new BaseResult();
        baseResult.setSuccess(ResultCodeEnum.SYSTEM_ERROE.getSuccess());
        baseResult.setCode(ResultCodeEnum.SYSTEM_ERROE.getCode());
        baseResult.setMsg(ResultCodeEnum.SYSTEM_ERROE.getMsg());
        baseResult.setData(null);
        return baseResult;
    }
    //参数错误返回
    public static BaseResult uploadErrorResult(){
        BaseResult baseResult = new BaseResult();
        baseResult.setSuccess(ResultCodeEnum.FILE_NOTFUND.getSuccess());
        baseResult.setCode(ResultCodeEnum.FILE_NOTFUND.getCode());
        baseResult.setMsg(ResultCodeEnum.FILE_NOTFUND.getMsg());
        baseResult.setData(null);
        return baseResult;
    }

    public static BaseResult uploadFailResult(){
        BaseResult baseResult = new BaseResult();
        baseResult.setSuccess(ResultCodeEnum.UPLOAD_FAILURE.getSuccess());
        baseResult.setCode(ResultCodeEnum.UPLOAD_FAILURE.getCode());
        baseResult.setMsg(ResultCodeEnum.UPLOAD_FAILURE.getMsg());
        baseResult.setData(null);
        return baseResult;
    }


    //通用返回
    public static BaseResult setResult(ResultCodeEnum result, Map<String,Object> data){
        BaseResult baseResult = new BaseResult();
        baseResult.setSuccess(result.getSuccess());
        baseResult.setCode(result.getCode());
        baseResult.setMsg(result.getMsg());
        baseResult.setData(data);
        return baseResult;
    }

}
